#!/bin/sh
# Copyright 2022 by Ron Yorston
# Licensed under GPLv2, see file LICENSE in this source tree.

. ./testing.sh

# testing "test name" "commands" "expected result" "file input" "stdin"

# Not so much a test of 'env' as of whether environment variables
# (or the lack thereof) are correctly passed to child processes.
testing "environment variables 1a" \
	"V=set env sh -c 'env | grep ^V='" \
	"V=set
" "" ""

testing "environment variables 1b" \
	"V= env sh -c 'env | grep ^V='" \
	"V=
" "" ""

testing "environment variables 1c" \
	"env sh -c 'env | grep ^V='" \
	"" "" ""

testing "environment variables 2a" \
	"V=set sh -c 'env | grep ^V='" \
	"V=set
" "" ""

testing "environment variables 2b" \
	"V= sh -c 'env | grep ^V='" \
	"V=
" "" ""

testing "environment variables 2c" \
	"sh -c 'env | grep ^V='" \
	"" "" ""

testing "environment variables 3a" \
	"V=set env sh -c 'echo \${V-unset}'" \
	"set
" "" ""

testing "environment variables 3b" \
	"V= env sh -c 'echo \${V-unset}'" \
	"
" "" ""

testing "environment variables 3c" \
	"env sh -c 'echo \${V-unset}'" \
	"unset
" "" ""

testing "environment variables 4a" \
	"V=set sh -c 'echo \${V-unset}'" \
	"set
" "" ""

testing "environment variables 4b" \
	"V= sh -c 'echo \${V-unset}'" \
	"
" "" ""

testing "environment variables 4c" \
	"sh -c 'echo \${V-unset}'" \
	"unset
" "" ""

exit $FAILCOUNT
